/*
 * Copyright (C) 2013 The i18nCTS Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.i18nCTS.view;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.googlecode.i18nCTS.provider.i18nCTSProvider;

public class RunAllSectionFragment extends AbstractSectionFragment {
	private static final String TAG = "I18nCTS_" + RunAllSectionFragment.class.getSimpleName();
	public static final String CATEGORY = "RunAll";

	public RunAllSectionFragment() {
		Log.d(TAG, "ctr");
	}
	
	@Override
	public String getCategory() {
		return CATEGORY;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// assign current context
		mContext = getActivity();		

		// fill the data
		i18nCTSProvider file = new i18nCTSProvider(mContext);
		buildList(file);
		
		// if (needed) export the test result
		file.exportXMLFile(getCategory());

		// display the context in the app client area as HTML
		WebView webView = new WebView(mContext);
		webView.loadData(file.getHTML(), "text/html; charset=UTF-8", null);
		
		return webView;
	}
	
	void buildCategoryList(i18nCTSProvider provider, AbstractSectionFragment absFragment) {
		absFragment.setContext(mContext);
		absFragment.buildList(provider);
		provider.fillExpected(absFragment.getCategory());
		provider.commit();		
 	}
	
	public void buildList(i18nCTSProvider provider) {
		// ******************* Verison 1.0 01-15-2013.  Do NOT modify the order *******************
		buildCategoryList(provider, new DateUtilsSingleDateSectionFragment());
		buildCategoryList(provider, new DateUtilsRangeDiffTimeSectionFragment());
		buildCategoryList(provider, new DateUtilsRangeSameMonthSectionFragment());
		buildCategoryList(provider, new DateUtilsRangeDiffMonthSectionFragment());
		buildCategoryList(provider, new DateUtilsRangeSameMonthDiffYearSectionFragment());
		buildCategoryList(provider, new DateUtilsRangeDiffMonthDiffYearSectionFragment());
		buildCategoryList(provider, new DateUtilsNoonMidnightSectionFragment());
		buildCategoryList(provider, new DateFormatSectionFragment());
		buildCategoryList(provider, new NumberSectionFragment());
		buildCategoryList(provider, new CalendarSectionFragment());
		buildCategoryList(provider, new StringSectionFragment());
		// ******************* End of verison 1.0 *******************

		// ******************* Verison 1.1 01-15-2013.  Do NOT modify the order *******************
		buildCategoryList(provider, new DateUtilsDayWeekdaySectionFragment());
		buildCategoryList(provider, new DateUtilsWeekdayTimeSectionFragment());
		// ******************* End of verison 1.0 *******************
	}

}
